package top.vanchor.myblog2back;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Ding
 * @create 2022/2/3 12:17
 */
public class javatest {
    public static void main(String[] args) {
        /**
         * step.1
         * 初始化牌盒
         * 并应用洗牌算法打乱
         */
        ArrayList<Map<String, Object>> pokerBox = new ArrayList<>();
        String[] colors = {"♦", "♥", "♠", "♣"};
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (String color : colors) {
            int i = 0;
            for (String number : numbers) {
                Map<String, Object> poker = new HashMap<>();
                poker.put("c", color);
                poker.put("n", number);
                poker.put("s", 0);
                pokerBox.add(poker);
            }
        }
        //加入大小王
        for (int i = 0; i < 2; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("c", String.valueOf(i));
            map.put("n", String.valueOf(i));
            map.put("s", 0);
            pokerBox.add(map);
        }
        Collections.shuffle(pokerBox);
        /**
         * step.2
         * 发牌
         */
        ArrayList<Map<String, Object>> userA = new ArrayList<>();
        ArrayList<Map<String, Object>> userB = new ArrayList<>();
        ArrayList<Map<String, Object>> hand = new ArrayList<>();
        for (int i = 0; i < pokerBox.size(); i++) {
            if (i >= pokerBox.size() - 3) {
                //底牌
                hand.add(pokerBox.get(i));
            } else if (i % 3 == 0) {
                userA.add(pokerBox.get(i));
            } else if (i % 3 == 1) {
                userB.add(pokerBox.get(i));
            }
        }

        /**
         * step.3
         * 对每张牌进行排序
         * 自定义算法
         */
        String[] sort = {"1", "0", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5","4","3"};
        ArrayList<Map<String,Object>> userA1 = new ArrayList<>();
        ArrayList<Map<String,Object>> userB1 = new ArrayList<>();
        for (String s : sort) {
            for (Map<String, Object> poker : userA) {
                if (poker.get("n").equals(s)){
                    userA1.add(poker);
                }
            }
        }
        for (String s : sort) {
            for (Map<String, Object> poker : userB) {
                if (poker.get("n").equals(s)){
                    userB1.add(poker);
                }
            }
        }

        System.err.println(pokerBox.size()+".."+userA1.size()+".."+userA.size());
        System.err.println(userA);
        System.err.println(userA1);
    }
}
